﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using PolePosition.v3.Common;
using PolePosition.v3.Desktop.Utility;
using PolePosition.v3.EntityLibrary;
using System.Collections.Generic;
using System.Diagnostics;

namespace PolePosition.v3.Desktop
{
    public partial class FormMain : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public FormMain()
        {
            InitializeComponent();

            // reference in program
            Program.FormMain = this;

            Visible = false;
            //hide all tabs
            tabItemHome.Visible = false;
            tabItemMap.Visible = false;
            tabItemData.Visible = false;
            tabItemOther.Visible = false;
            tabItemReports.Visible = false;
            tabItemWorkQueue.Visible = false;
            tabItemDirections.Visible = false;

            //start load of lookup tables immediately
            backgroundWorkerLoadLookupTables.RunWorkerAsync();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            FormLogin _Login = new FormLogin();

            // handle failed login
            if (_Login.ShowDialog() != DialogResult.OK)
            {
                if (backgroundWorkerLoadLookupTables.IsBusy)
                    backgroundWorkerLoadLookupTables.CancelAsync();
                Application.Exit();
                return;
            }

            // set the appropriate tab to visible
            switch (Program.LoginResult.LoginUserType)
            {
                case LoginEntity.LoginUserTypes.Vendor:
                    ribbonTabItemAdmin.Visible = false;
                    ribbonTabItemUtilityHome.Visible = false;
                    ribbonTabItemVendorHome.Visible = true;
                    ribbonTabItemVendorHome.Select();
                    break;
                case LoginEntity.LoginUserTypes.Utility:
                    ribbonTabItemAdmin.Visible = false;
                    ribbonTabItemUtilityHome.Visible = true;
                    ribbonTabItemVendorHome.Visible = false;
                    ribbonTabItemUtilityHome.Select();

                    // a little customization - put utility name in the ribbon group
                    if (Program.LoginResult.Utility != null && !string.IsNullOrEmpty(Program.LoginResult.Utility.Name))
                        ribbonBarUtilityProjects.Text = Program.LoginResult.Utility.Name;

                    Program.UserSelections.UtilityId = Program.LoginResult.Utility.UtilityId.Value;

                    break;
                case LoginEntity.LoginUserTypes.PPI:

                    if (Program.LoginResult.Utilities == null ||
                        Program.LoginResult.Utilities.Count() != 1)
                    {
                        ribbonBarPPIUtility.Visible = true;
                        buttonItemUtilityProjectViewInGrid.Enabled = false;
                        buttonItemUtilityProjectViewReports.Enabled = false;
                        buttonItemUtilityProjectViewWorkQueue.Enabled = false;
                        buttonItemUtiltyProjectViewInMap.Enabled = false;

                        buttonItemUtilityProjectViewSelectUtility.Visible = true;
                    }

                    ribbonTabItemAdmin.Visible = true;
                    ribbonTabItemUtilityHome.Visible = true;
                    ribbonTabItemVendorHome.Visible = true;
                    ribbonTabItemAdmin.Select();
                    break;
                case PolePosition.v3.EntityLibrary.LoginEntity.LoginUserTypes.Unknown:
                default:
                    Debug.Assert(false, "This case should not be possible");
                    break;
            }

            //try to do vendor setup (dual entry point: after lookup data retrieval and login - both must be done)
            DoVendorSetup();

            Visible = true;
        }

        public TabMap.MapDisplay MapControl
        {
            get
            {
                return tabMap1.Map;
            }
        }

        public void ShowMapTab()
        {
            return;
            tabItemMap.Visible = true;
            tabControlMain.SelectedTab = tabItemMap;
        }

        private void backgroundWorkerLoadLookupTables_DoWork(object sender, DoWorkEventArgs e)
        {
            e.Result = ServiceProxy.AdministrationService.GetLookups();

            if ((sender as BackgroundWorker).CancellationPending)
                e.Cancel = true;
        }

        private void backgroundWorkerLoadLookupTables_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
                return;

            if (e.Error != null)
            {
                //not really sure what to do here - for now show a messagebox and close the app
                DevComponents.DotNetBar.MessageBoxEx.Show("A Critical Error has occurred attempting to load the application. Application will close. (ref:lookup)", "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }

            Program.LookupTableData = e.Result as EntityLibrary.LookupTables;

            //try to do vendor setup (dual entry point: after lookup data retrieval and login - both must be done)
            DoVendorSetup();
        }

        #region Vendor Setup Background Process
        
        private bool m_VendorSetupStarted = false;
        private void DoVendorSetup()
        {
            if (m_VendorSetupStarted)
                return;

            if (Program.LoginResult == null)
                return;

            if (Program.LookupTableData == null)
                return;

            m_VendorSetupStarted = true;

            //not needed for utility
            if (Program.LoginResult.LoginUserType == LoginEntity.LoginUserTypes.Utility)
                return;

            DesktopFactory.MobileSetup.DownloadPrerequisiteFilesComplete += new EventHandler(MobileSetup_DownloadPrerequisiteFilesComplete);

            //begin folder setup and load of vendor prerequisite files
            backgroundWorkerVendorSetup.RunWorkerAsync();
        }

        private void MobileSetup_DownloadPrerequisiteFilesComplete(object sender, EventArgs e)
        {
            DesktopFactory.MobileSetup.DownloadPrerequisiteFilesComplete -= new EventHandler(MobileSetup_DownloadPrerequisiteFilesComplete);

            Program.UserSelections.VendorSetupComplete = true;
        }

        private void backgroundWorkerVendorSetup_DoWork(object sender, DoWorkEventArgs e)
        {   
            DesktopFactory.MobileSetup.DoDirectorySetup();

            string _FilesToDownload;
            _FilesToDownload = Program.GetSettingValue(Constants.Settings.PrerequisiteFileList);

            if (string.IsNullOrEmpty(_FilesToDownload))
                return;

            List<string> _FileList;
            _FileList = _FilesToDownload.Split(',').ToList();

          

            DesktopFactory.MobileSetup.DownloadPrerequisiteFiles(_FileList);
        }
     
        private void backgroundWorkerVendorSetup_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //
        }

        #endregion


        #region Utility Ribbon Buttons

        private void buttonItemUtiltyProjectViewInMap_Click(object sender, EventArgs e)
        {
            var _MapElements = new Selectors.SelectMapElements();
            if (_MapElements.ShowDialog() == DialogResult.OK)
            {
                //load map
                ShowMapTab();
                MapControl.LoadKmlFromString(Enumerations.DataTypes.Custom, _MapElements.Kml);
            }
        }

        private void buttonItemUtiltyProjectViewInMap2_Click(object sender, EventArgs e)
        {
            string kml = string.Empty;

            switch (Program.LoginResult.LoginUserType)
            {
                case LoginEntity.LoginUserTypes.Utility:
                    kml = ServiceProxy.UtilityService.GetUtilityKMLString(Program.LoginResult.Utility.UtilityId, Program.LoginResult.UtilityContact.Utility_ContactId);
                //case LoginEntity.LoginUserTypes.Vendor:
                   
                break;
            }

            //load map
            ShowMapTab();
            MapControl.LoadKmlFromString(Enumerations.DataTypes.Custom, kml);
        } 

        private void buttonItemProjectData_Click(object sender, EventArgs e)
        {
            string _ProjectName = null;
            int? _ProjectId = null;
            Common.Enumerations.DataTypes _ProjectType = Enumerations.DataTypes.None;

            if (Program.LoginResult.Projects == null ||
               Program.LoginResult.Projects.Count() != 1)
            {
                if (!Selectors.Helper.SelectProject(out _ProjectId, out _ProjectName, out _ProjectType))
                {
                    // todo: do something
                }
            }
            else
            {
                _ProjectId = Program.LoginResult.Projects[0].Vendor_ProjectId;
                _ProjectName = Program.LoginResult.Projects[0].Name;

                if (Program.LoginResult.Projects[0].ProjectTypeFk.Value == Constants.ProjectTypes.XmissionGpsVisit)
                    _ProjectType = Enumerations.DataTypes.ProjectsXmissionGpsVisit;
                else if (Program.LoginResult.Projects[0].ProjectTypeFk.Value == Constants.ProjectTypes.XmissionInspection)
                    _ProjectType = Enumerations.DataTypes.ProjectsXmissionInspection;
                else if (Program.LoginResult.Projects[0].ProjectTypeFk.Value == Constants.ProjectTypes.DistributionInspection)
                    _ProjectType = Enumerations.DataTypes.ProjectsDistributionInspection;
            }

            if (!_ProjectId.HasValue || _ProjectType == Enumerations.DataTypes.None)
                return;

            //load grid
            tabItemData.Visible = true;
            tabControlMain.SelectedTab = tabItemData;
            switch (_ProjectType)
            {
                case Enumerations.DataTypes.ProjectsXmissionInspection:
                    tabData1.ShowXmissionInspectionData(_ProjectId.Value, _ProjectName);
                    break;
                case Enumerations.DataTypes.ProjectsXmissionGpsVisit:
                    tabData1.ShowXmissionGPSData(_ProjectId.Value, _ProjectName);
                    break;
                case Enumerations.DataTypes.ProjectsDistributionInspection:
                    tabData1.ShowDistributionInspectionData(_ProjectId.Value, _ProjectName);
                    break;
                case Enumerations.DataTypes.ProjectsDistributionGpsVisit:
                    break;
                default:
                    break;
            }
        }

        private void buttonItemAssetData_Click(object sender, EventArgs e)
        {
            Selectors.SelectDataElements _DataElements = new Selectors.SelectDataElements(Selectors.SelectDataElements.SelectDataElementTypes.Assets);
            if (_DataElements.ShowDialog() == DialogResult.OK)
            {
                //load grid
                tabItemData.Visible = true;

                switch (_DataElements.SelectedType)
                {
                    case Enumerations.DataTypes.AssetsXmission:
                        tabData1.ShowXmissionAssetData();
                        break;
                    case Enumerations.DataTypes.AssetsDistribution:
                        tabData1.ShowDistibutionAssetData();
                        break;
                    case Enumerations.DataTypes.AssetsMeters:
                        tabData1.ShowMeterAssetData();
                        break;
                    case Enumerations.DataTypes.AssetsTransformers:
                        tabData1.ShowTransformerAssetData();
                        break;
                    default:
                        break;
                }
            }
        }

        private void buttonItemUtilityProjectViewReports_Click(object sender, EventArgs e)
        {
            string _ProjectName = null;
            int? _ProjectId = null;
            Common.Enumerations.DataTypes _ProjectType = Enumerations.DataTypes.None;

            if (Program.LoginResult.Projects == null ||
               Program.LoginResult.Projects.Count() != 1)
            {
                Selectors.SelectDataElements _DataElements = new Selectors.SelectDataElements(Selectors.SelectDataElements.SelectDataElementTypes.Projects);
                if (_DataElements.ShowDialog() == DialogResult.OK)
                {
                    _ProjectId = _DataElements.SelectedId;
                    _ProjectName = _DataElements.SelectedName;
                    _ProjectType = _DataElements.SelectedType;
                }
                _DataElements.Dispose();
            }
            else
            {
                _ProjectId = Program.LoginResult.Projects[0].Vendor_ProjectId;
                _ProjectName = Program.LoginResult.Projects[0].Name;

                if (Program.LoginResult.Projects[0].ProjectTypeFk.Value == Constants.ProjectTypes.XmissionGpsVisit)
                    _ProjectType = Enumerations.DataTypes.ProjectsXmissionGpsVisit;
                else if (Program.LoginResult.Projects[0].ProjectTypeFk.Value == Constants.ProjectTypes.XmissionInspection)
                    _ProjectType = Enumerations.DataTypes.ProjectsXmissionInspection;
                else if (Program.LoginResult.Projects[0].ProjectTypeFk.Value == Constants.ProjectTypes.DistributionInspection)
                    _ProjectType = Enumerations.DataTypes.ProjectsDistributionInspection;
            }

            if (!_ProjectId.HasValue || _ProjectType == Enumerations.DataTypes.None)
                return;

            //load reports tab
            tabItemReports.Visible = true;
            tabControlMain.SelectedTab = tabItemReports;
            tabReports1.ShowReports(Program.UserSelections.UtilityId, _ProjectId.Value, _ProjectName, _ProjectType);
        }

        private void buttonItemUtilityProjectViewWorkQueue_Click(object sender, EventArgs e)
        {
            tabItemWorkQueue.Visible = true;
            tabControlMain.SelectedTab = tabItemWorkQueue;
            tabWorkQueue1.ShowWorkQueueData();
        }

        private void buttonItemUtilityProjectViewSelectUtility_Click(object sender, EventArgs e)
        {
            Selectors.SelectUtility _SelectUtility = new Selectors.SelectUtility();
            _SelectUtility.ShowDialog();
            _SelectUtility.Dispose();

            if (Program.UserSelections.UtilityId == -1)
            {
                buttonItemUtilityProjectViewInGrid.Enabled = false;
                buttonItemUtilityProjectViewReports.Enabled = false;
                buttonItemUtilityProjectViewWorkQueue.Enabled = false;
                buttonItemUtiltyProjectViewInMap.Enabled = false;
                ribbonBarUtilityProjects.Text = "Utility";
            }
            else
            {
                buttonItemUtilityProjectViewInGrid.Enabled = true;
                buttonItemUtilityProjectViewReports.Enabled = true;
                buttonItemUtilityProjectViewWorkQueue.Enabled = true;
                buttonItemUtiltyProjectViewInMap.Enabled = true;

                var _DefaultUtility = from utility in Program.LoginResult.Utilities
                                      where utility.UtilityId == Program.UserSelections.UtilityId
                                      select utility;

                if (_DefaultUtility == null || _DefaultUtility.Count() == 0)
                    ribbonBarUtilityProjects.Text = "Utility";
                else
                    ribbonBarUtilityProjects.Text = _DefaultUtility.First().Name;
            }
        }

        #endregion

        #region Vendor Ribbon Buttons

        #region Project Ribbon Group

        private void buttonItemVendorProjectViewLoad_Click(object sender, EventArgs e)
        {
            Selectors.SelectProject _Project = new Selectors.SelectProject();
            if (_Project.ShowDialog() == DialogResult.OK)
            {
                if (Program.UserSelections.VendorSelectedProject == null)
                {
                    ribbonBarVendorProjects.Text = "Project";
                    buttonItemVendorProjectUploadToServer.Enabled = false;
                    buttonItemVendorProjectViewData.Enabled = false;
                    buttonItemVendorProjectViewReports.Enabled = false;
                    buttonItemVendorMobileCopyFromSD.Enabled = false;
                    buttonItemVendorMobileDeploytoSD.Enabled = false;
                    buttonItemVendorMobileOpenLocalData.Enabled = false;
                }
                else
                {
                    ribbonBarVendorProjects.Text = Program.UserSelections.VendorSelectedProject.Name;
                    buttonItemVendorProjectUploadToServer.Enabled = true;
                    buttonItemVendorProjectViewData.Enabled = true;
                    buttonItemVendorProjectViewReports.Enabled = true;
                    buttonItemVendorMobileCopyFromSD.Enabled = true;
                    buttonItemVendorMobileDeploytoSD.Enabled = true;
                    buttonItemVendorMobileOpenLocalData.Enabled = true;
                }
            }
        }

        private void buttonItemVendorProjectViewMap_Click(object sender, EventArgs e)
        {

        }

        private void buttonItemVendorProjectViewData_Click(object sender, EventArgs e)
        {
            string _ProjectName = null;
            int? _ProjectId = null;
            Common.Enumerations.DataTypes _ProjectType = Enumerations.DataTypes.None;

            if (Program.LoginResult.Projects == null ||
               Program.LoginResult.Projects.Count() != 1)
            {
                if (!Selectors.Helper.SelectProject(out _ProjectId, out _ProjectName, out _ProjectType))
                {
                    // todo: do something
                }
            }
            else
            {
                _ProjectId = Program.LoginResult.Projects[0].Vendor_ProjectId;
                _ProjectName = Program.LoginResult.Projects[0].Name;

                if (Program.LoginResult.Projects[0].ProjectTypeFk.Value == Constants.ProjectTypes.XmissionGpsVisit)
                    _ProjectType = Enumerations.DataTypes.ProjectsXmissionGpsVisit;
                else if (Program.LoginResult.Projects[0].ProjectTypeFk.Value == Constants.ProjectTypes.XmissionInspection)
                    _ProjectType = Enumerations.DataTypes.ProjectsXmissionInspection;
                else if (Program.LoginResult.Projects[0].ProjectTypeFk.Value == Constants.ProjectTypes.DistributionInspection)
                    _ProjectType = Enumerations.DataTypes.ProjectsDistributionInspection;
            }

            if (!_ProjectId.HasValue || _ProjectType == Enumerations.DataTypes.None)
                return;

            //load grid
            tabItemData.Visible = true;
            tabControlMain.SelectedTab = tabItemData;
            switch (_ProjectType)
            {
                case Enumerations.DataTypes.ProjectsXmissionInspection:
                    tabData1.ShowXmissionInspectionData(_ProjectId.Value, _ProjectName);
                    break;
                case Enumerations.DataTypes.ProjectsXmissionGpsVisit:
                    tabData1.ShowXmissionGPSData(_ProjectId.Value, _ProjectName);
                    break;
                case Enumerations.DataTypes.ProjectsDistributionInspection:
                    tabData1.ShowDistributionInspectionData(_ProjectId.Value, _ProjectName);
                    break;
                case Enumerations.DataTypes.ProjectsDistributionGpsVisit:
                    // TODO: show
                    break;
                default:
                    break;
            }
        }

        private void buttonItemVendorProjectViewReports_Click(object sender, EventArgs e)
        {
            //
        }

        #endregion

        #region Mobile Ribbon Group

        private void buttonItemVendorMobileDeploytoSD_Click(object sender, EventArgs e)
        {
            Editors.DeployToCard _DeployToCard;
            _DeployToCard = new Editors.DeployToCard();
            _DeployToCard.ShowDialog();
            _DeployToCard.Dispose();

        }

        private void buttonItemVendorMobileDeploy_Click(object sender, EventArgs e)
        {
            //
        }

        private void buttonItemVendorMobileRetrieve_Click(object sender, EventArgs e)
        {
            //
        }

        #endregion
       
        #endregion

        private void buttonXTestKml_Click(object sender, EventArgs e)
        {
            string _Kml;
            _Kml = ServiceProxy.UtilityService.TestKml();
            MapControl.LoadKmlFromString(Enumerations.DataTypes.Custom, _Kml);
        }

        public void ShowDirections(string title, string url)
        {
            if (string.IsNullOrEmpty(title))
                title = "Directions";

            tabItemDirections.Visible = true;
            tabControlMain.SelectedTab = tabItemDirections;
            tabItemDirections.Text = title;
            tabBrowser1.ShowBrowser(title, url);
        }

        private void tabControlMain_TabItemClose(object sender, DevComponents.DotNetBar.TabStripActionEventArgs e)
        {
            e.Cancel = true;
            tabControlMain.SelectedTab.Visible = false;
        }

        private void buttonItemHelp_Click(object sender, EventArgs e)
        {
            tabItemDirections.Visible = true;
            tabControlMain.SelectedTab = tabItemDirections;
            tabItemDirections.Text = "Pole Position Help";
            tabBrowser1.ShowBrowser("Pole Position Help", "http://dev-poleposition.com/PolePosition/Help/default.htm");
        }

        private void txtOnlyNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != (char)Keys.Back;
        }

        private void buttonItemUtiltyProjectViewInMap_PopupOpen(object sender, DevComponents.DotNetBar.PopupOpenEventArgs e)
        {
            txtInspectionVisitNumber.TextBox.Text = string.Empty;
            txtDistributionVisitNumber.TextBox.Text = string.Empty;
            txtMeterNumber.TextBox.Text = string.Empty;
            txtDistributionAssetNumber.TextBox.Text = string.Empty;
            txtTransmissionAssetNumber.TextBox.Text = string.Empty;

            txtDistributionVisitNumber.TextBox.TextAlign = HorizontalAlignment.Right;
            txtInspectionVisitNumber.TextBox.TextAlign = HorizontalAlignment.Right;
            txtMeterNumber.TextBox.TextAlign = HorizontalAlignment.Right;
            txtDistributionAssetNumber.TextBox.TextAlign = HorizontalAlignment.Right;
            txtTransmissionAssetNumber.TextBox.TextAlign = HorizontalAlignment.Right;
        }

        private void txtInspectionVisitNumber_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnGoInspectionVisit_Click(sender, e);
        }

        private void txtDistributionVisitNumber_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnGoDistributionVisit_Click(sender, e);
        }

        private void txtDistributionAssetNumber_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnGoDistributionAsset_Click(sender, e);
        }

        private void txtTransmissionAssetNumber_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnGoTransmisionAsset_Click(sender, e);
        }

        private void txtMeterNumber_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnGoMeterAsset_Click(sender, e);
        }

        private void buttonItemUtilityProjectViewAssetassociations_Click(object sender, EventArgs e)
        {
            Form formAssetAssociations = new AssetAssociations();

            formAssetAssociations.Show(this);
        }

        private void buttonAssetsAssociations_Click(object sender, EventArgs e)
        {
            if (Program.UserSelections.UtilityId <= 0)
                buttonItemUtilityProjectViewSelectUtility_Click(sender, e);

            if (Program.UserSelections.UtilityId <= 0)
                return;

            if (Program.UserSelections.VendorSelectedProject == null || Program.UserSelections.VendorSelectedProject.Vendor_ProjectId <= 0)
                buttonItemVendorProjectViewLoad_Click(sender, e);

            if (Program.UserSelections.VendorSelectedProject == null || Program.UserSelections.VendorSelectedProject.Vendor_ProjectId <= 0)
                return;

            var _DataElements = new Selectors.SelectDataElements(Selectors.SelectDataElements.SelectDataElementTypes.Assets);
            
            if (_DataElements.ShowDialog() == DialogResult.OK)
            {
                //load grid
                tabItemData.Visible = true;

                switch (_DataElements.SelectedType)
                {
                    case Enumerations.DataTypes.AssetsXmission:
                        if (Program.UserSelections.VendorSelectedProject.ProjectTypeFk == Constants.ProjectTypes.XmissionGpsVisit)
                            tabData1.ShowXMissionVisitToAssetData();
                        else if (Program.UserSelections.VendorSelectedProject.ProjectTypeFk == Constants.ProjectTypes.XmissionInspection)
                            tabData1.ShowXMissionInspectionToAssetData();
                        break;
                    case Enumerations.DataTypes.AssetsDistribution:
                        tabData1.ShowDistributionInspToAssetData();
                        break;
                    case Enumerations.DataTypes.AssetsMeters:
                        tabData1.ShowDistributionMeterToAssetData();
                        break;
                    default:
                        break;
                }
            }
        }

        #region - Quick Search -

        private void btnGoInspectionVisit_Click(object sender, EventArgs e)
        {
            var result = ServiceProxy.UtilityService.QuickSearch(Program.LoginResult.Utility.UtilityId, txtInspectionVisitNumber.TextBox.Text, Enumerations.DataTypes.ProjectsXmissionInspection);

            if (result.Equals(string.Empty))
                DevComponents.DotNetBar.MessageBoxEx.Show("No result found", "Search message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
                MapControl.LoadKmlFromString(Enumerations.DataTypes.Custom, result);
        }

        private void btnGoDistributionVisit_Click(object sender, EventArgs e)
        {
            var result = ServiceProxy.UtilityService.QuickSearch(Program.LoginResult.Utility.UtilityId, txtDistributionVisitNumber.TextBox.Text, Enumerations.DataTypes.ProjectsDistributionInspection);

            if (result.Equals(string.Empty))
                DevComponents.DotNetBar.MessageBoxEx.Show("No result found", "Search message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
                MapControl.LoadKmlFromString(Enumerations.DataTypes.Custom, result);
        }

        private void btnGoMeterAsset_Click(object sender, EventArgs e)
        {
            var result = ServiceProxy.UtilityService.QuickSearch(Program.LoginResult.Utility.UtilityId, txtMeterNumber.TextBox.Text, Enumerations.DataTypes.AssetsMeters);

            if (result.Equals(string.Empty))
                DevComponents.DotNetBar.MessageBoxEx.Show("No result found", "Search message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
                MapControl.LoadKmlFromString(Enumerations.DataTypes.Custom, result);
        }

        private void btnGoDistributionAsset_Click(object sender, EventArgs e)
        {
            var result = ServiceProxy.UtilityService.QuickSearch(Program.LoginResult.Utility.UtilityId, txtDistributionAssetNumber.TextBox.Text, Enumerations.DataTypes.AssetsDistribution);

            if (result.Equals(string.Empty))
                DevComponents.DotNetBar.MessageBoxEx.Show("No result found", "Search message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
                MapControl.LoadKmlFromString(Enumerations.DataTypes.Custom, result);
        }

        private void btnGoTransmisionAsset_Click(object sender, EventArgs e)
        {
            var result = ServiceProxy.UtilityService.QuickSearch(Program.LoginResult.Utility.UtilityId, txtTransmissionAssetNumber.TextBox.Text, Enumerations.DataTypes.AssetsXmission);

            if (result.Equals(string.Empty))
                DevComponents.DotNetBar.MessageBoxEx.Show("No result found", "Search message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
                MapControl.LoadKmlFromString(Enumerations.DataTypes.Custom, result);

        }

        #endregion
    }
}
